<!DOCTYPE html>
<html>
    <head>
        <title>W3C DOM L3 Event: CustomEvent</title>
        <script type="text/javascript">
            var PassTest = function()
            {
                document.getElementById("testresult").firstChild.data = "PASS";
            }

            var FailTest = function()
            {
                document.getElementById("testresult").firstChild.data = "FAIL";
            }

            var EVENT = "foo";
            var TARGET;

            window.onload = function()
            {
                try
                {
                    TARGET = document.getElementById("target");
                    TARGET.addEventListener(EVENT, TestCapture, true);

                    var fooEvent = document.createEvent("CustomEvent");
                    fooEvent.initEvent(EVENT, true, true);
                    TARGET.dispatchEvent(fooEvent);
                }
                catch(ex)
                {
                    FailTest();
                }
            }

            function TestCapture(evt)
            {
                if ((evt.type == EVENT))
                {
                    PassTest();
                }
                else
                {
                    FailTest();
                }
            }
        </script>
    </head>
    <body>
        <h4>
            Test Description:
            Create and fire CustomEvent using methods: createEvent, initEvent, dispatchEvent.
        </h4>

        <input type="hidden" id="target" />

        <p>Test passes if the word "PASS" appears below.</p>
       	<div>Test result: </div>
        <div id='testresult'>FAIL</div>
    </body>
</html>
